package com.zj.fx.controller.info;

import com.zj.fx.common.base.BaseController;
import com.zj.fx.common.domain.AjaxResult;
import com.zj.fx.common.domain.ResultTable;
import com.zj.fx.model.custom.Tablepar;
import com.github.pagehelper.PageInfo;
import com.zj.fx.model.info.InfoSupply;
import com.zj.fx.model.info.InfoSupplyExample;
import com.zj.fx.service.info.InfoSupplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 供电所信息表Controller
 * @ClassName: InfoSupplyController
 * @author fuce
 * @date 2023-06-06 14:27:04
 */
@Api(value = "供电所信息表")
@Controller
@RequestMapping("/InfoSupplyController")
public class InfoSupplyController extends BaseController {

    private String prefix = "info/infoSupply";

    @Autowired
    private InfoSupplyService infoSupplyService;


    /**
     * 供电所信息表页面展示
     * @param model
     * @return String
     * @author fuce
     */
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/view")
    @RequiresPermissions("gen:infoSupply:view")
    public String view(ModelMap model) {
        return prefix + "/list";
    }

    /**
     * list集合
     * @param tablepar
     * @param
     * @return
     */
    //@Log(title = "供电所信息表", action = "111")
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/list")
    @RequiresPermissions("gen:infoSupply:list")
    @ResponseBody
    public ResultTable list(Tablepar tablepar, InfoSupply infoSupply) {
        PageInfo<InfoSupply> page = infoSupplyService.list(tablepar,infoSupply);
        return pageTable(page.getList(), page.getTotal());
    }

    /**
     * 新增跳转
     */
    @ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
        return prefix + "/add";
    }

    /**
     * 新增保存
     * @param 
     * @return
     */
    //@Log(title = "供电所信息表新增", action = "111")
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    @RequiresPermissions("gen:infoSupply:add")
    @ResponseBody
    public AjaxResult add(InfoSupply infoSupply) {
        int b = infoSupplyService.insertSelective(infoSupply);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }

    /**
     * 供电所信息表删除
     * @param ids
     * @return
     */
    //@Log(title = "供电所信息表删除", action = "111")
    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/remove")
    @RequiresPermissions("gen:infoSupply:remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        int b = infoSupplyService.deleteByPrimaryKey(ids);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }


    /**
     * 修改跳转
     * @param id
     * @param
     * @return
     */
    @ApiOperation(value = "修改跳转", notes = "修改跳转")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map) {
        map.put("InfoSupply", infoSupplyService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    //@Log(title = "供电所信息表修改", action = "111")
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("gen:infoSupply:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InfoSupply infoSupply) {
        return toAjax(infoSupplyService.updateByPrimaryKeySelective(infoSupply));
    }

    /**
     * 首页看板list集合(不分页)
     * @param infoSupply
     * @param
     * @return
     */
    //@Log(title = "供电所信息表", action = "111")
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/list4index")
    @ResponseBody
    public Map<String, Object> list4index(InfoSupply infoSupply) {
        Map<String, Object> map = new HashMap<>();
        InfoSupplyExample infoSupplyExample= new InfoSupplyExample();
        infoSupplyExample.createCriteria().andIdIsNotNull();
        List<InfoSupply> supplyList = infoSupplyService.selectByExample(infoSupplyExample);
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", supplyList.size());
        map.put("data", supplyList);
        return map;
    }

}
